<template>
	<view class="charts-box">
		<qiun-data-charts type="pie" :opts="opts" :chartData="chartData" :tooltipShow="false" />
	</view>
</template>

<script>
	import {
		echartWorkOrderCount
	} from '../../apis';
	export default {
		data() {

			return {
				chartData: {},
				//这里的 opts 是图表类型 type="pie" 的全部配置参数，您可以将此配置复制到 config-ucharts.js 文件中下标为 ['pie'] 的节点中来覆盖全局默认参数。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
				opts: {
					timing: "easeOut",
					duration: 1000,
					rotate: false,
					rotateLock: false,
					color: ['#fa7d7d', '#f7b77c', '#6fde7f', '#67dde0', '#77aeed'],
					padding: [5, 5, 5, 5],
					fontSize: 13,
					fontColor: "#666666",
					dataLabel: true,
					dataPointShape: false,
					dataPointShapeType: "hollow",
					touchMoveLimit: 60,
					enableScroll: false,
					enableMarkLine: false,
					legend: {
						show: true,
						position: "right",
						float: "center",
						padding: 20,
						backgroundColor: "rgba(0,0,0,0)",
						borderColor: "rgba(0,0,0,0)",
						borderWidth: 0,
						fontSize: 13,
						fontColor: "#666666",
						lineHeight: 30,
						hiddenColor: "#CECECE",
						itemGap: 10
					},
					extra: {
						pie: {
							activeOpacity: 0.5,
							activeRadius: 10,
							offsetAngle: 0,
							labelWidth: 15,
							border: false,
							borderWidth: 3,
							borderColor: "#FFFFFF",
							customRadius: 0,
							linearType: "none"
						},
						tooltip: {
							showBox: false,
							showArrow: false,
							showCategory: false,
							borderWidth: 0,
							borderRadius: 0,
							borderColor: "#000000",
							borderOpacity: 0.7,
							bgColor: "#000000",
							bgOpacity: 0.7,
							gridType: "solid",
							dashLength: 4,
							gridColor: "#CCCCCC",
							fontColor: "#FFFFFF",
							splitLine: false,
							horizentalLine: false,
							xAxisLabel: false,
							yAxisLabel: false,
							labelBgColor: "#FFFFFF",
							labelBgOpacity: 0.7,
							labelFontColor: "#666666"
						}
					}
				}
			};
		},
		mounted() {
			// this.$nextTick(this.renderCharts)
				
		},
		methods: {
			async renderCharts() {
				const res = await echartWorkOrderCount()
				console.log(res, 'res');
				const {
					body
				} = res
				const obj = {
					'processing': {
						value: 0,
						name: '处理中'
					},
					'waitAccept': {
						value: 0,
						name: '待接单'
					},
					'terminated': {
						value: 0,
						name: '已终止'
					},
					'waitAudit': {
						value: 0,
						name: '待审核'
					},
					'notPassAudit': {
						value: 0,
						name: '审核未通过'
					},
					'waitAppraisal': {
						value: 0,
						name: '待评价'
					},
					'ended': {
						value: 0,
						name: '已结束'
					},
				}
				for (let i in body) { 
				if (obj[i]) {
						obj[i].value = body[i] || 0
					}
				}  
				console.log(obj,'obj');
				const charData = {
					series: [{
						data: Object.values(obj)
					}]
				};
				
				this.chartData = JSON.parse(JSON.stringify(charData));
			},
		}
	};
</script>

<style scoped>
	/* 请根据实际需求修改父元素尺寸，组件自动识别宽高 */
	.charts-box {
		width: 100%;
		height: 300px;
	}
</style>
